package cn.lanca.gof6_10._07adapter.case2.adapter;

import com.example.demo.gof6_10._07adapter.case2.adaptee.ElectricMotor;
import com.example.demo.gof6_10._07adapter.case2.target.Motor;

/**
 * 电能适配器
 *
 * @author meihongliang
 * @since 2020/8/10 16:34
 */
public class ElectricAdapter implements Motor {

    /**
     * electricMotor
     */
    private ElectricMotor electricMotor;

    /**
     * Class<?> c = Class.forName(cName);
     * Object obj = c.newInstance();
     * forName方法需要无参构造器,且适配器模式用的对象会出现null现象,因此,得new个适配器对象处来
     */
    public ElectricAdapter() {
        this.electricMotor = new ElectricMotor();
    }

    /**
     * construct 构造器
     *
     * @param electricMotor
     */
    public ElectricAdapter(ElectricMotor electricMotor) {
        this.electricMotor = electricMotor;
    }

    /**
     * 驾驶
     */
    @Override
    public void drive() {
        electricMotor.electricDrive();
    }
}
